#include<iostream>
using namespace std;
class ListNode {
public:
	int n;
	ListNode* pre;
	ListNode* next;
	ListNode() {
		pre = NULL;
		next = NULL;
	}
};
class List {
public:
	ListNode* head;
	int len;
	List() {
		head = new ListNode;
		len = 0;
	}
	~List() {
		ListNode* p = head;
		while (p != NULL) {
			head = head->next;
			delete p;
			p = head;
		}
	}
	void Insert(int n) {
		ListNode* p = new ListNode;
		p->n = n;
		ListNode* q = head;
		while (q->next != NULL) {
			q = q->next;
		}
		q->next = p;
		p->pre = q;
		len++;
	}
	void print(int n) {
		ListNode* p = head->next;
		while (p != NULL) {
			if (p->n == n) {
				if (p->pre == head) {
					if (p->next != NULL) {
						cout << p->next->n << endl;
					}
				}
				else {
					cout << p->pre->n << ' ';
					if (p->next != NULL) {
						cout << p->next->n << endl;
					}
					else {
						cout << endl;
					}
				}
			}
			p = p->next;
		}
	}
};
int main()
{
	List L;
	int n, m;
	cin >> n >> m;
	int num;
	for (int i = 0; i < n; i++) {
		cin >> num;
		L.Insert(num);
	}
	for (int i = 0; i < m; i++) {
		cin >> num;
		L.print(num);
	}
	return 0;
}